﻿/** 
 * Description:
 * Date:2011-9-5
 * Author:Along	
*/
package com.community.shopping.web;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.community.shopping.service.logic.GoodsTypeManager;
import com.community.shopping.util.FreeMarkerUtil;
import com.community.shopping.util.RequestHelp;
@Controller 
public class IndexControl {
	 @Autowired  
	 private GoodsTypeManager goodsTypeManager;   
	@RequestMapping("/index/*")
	//进入首页
	 public ModelAndView index(HttpServletRequest request,HttpServletResponse response) throws Exception
     { 
           Integer shopId=RequestHelp.getShopId(request);
	       String folder=request.getSession().getServletContext().getRealPath("/")+"cache/";
	       File indexFile=new File(folder+"index_"+shopId+".html");
	       if(!indexFile.exists()|| true)
	       {
	    	   List goodstypes=goodsTypeManager.getTopGoodsType(shopId);
	    	   Map root=new HashMap();
	      	   root.put("goodstypes", goodstypes);
	           FreeMarkerUtil.getInstance(request.getSession().getServletContext()).createHTML("index.ftl", root, indexFile); 	    	   
	       }
	       ModelAndView modelAndView = new ModelAndView("/cache/"+"index_"+shopId+".html");  	  
		   return modelAndView;
	  } 
	
	@RequestMapping("/mobile/mobile")
	 public ModelAndView mobile(HttpServletRequest request) 
    { 
      ModelAndView modelAndView = new ModelAndView("mobile.jsp"); 
      Integer shopId=RequestHelp.getShopId(request);
	  List topGoodsTypes=goodsTypeManager.getTopGoodsType(shopId); 
	  modelAndView.addObject("topgoodstypes", topGoodsTypes); 
	   //List leftTypes=goodsTypeManager.getGoodsTypeByUp((GoodsType)topGoodsTypes.get(0));
	   //modelAndView.addObject("leftgoodstype", leftTypes); 
      return modelAndView; 		

	  } 
}
